Package, Crate, and Modules
Overview
複雑なプロジェクト
実装とAPIの分離にも役立つ
スコープの概念
キーワード
- Packages(Rust): A Cargo feature that lets you build, test, and share crates - Crates: A tree of modules that produces a library or executable - Modules(Rust) and use: Let you control the organization, scope, and privacy of paths - Paths(Rust): A way of naming an item, such as a struct, function, or module TOC
Packages and Crates
Defining Modules to Control Scope and Privacy
Paths for Referring to an Item in the Module Tree
Bringing Paths Into Scope with the use Keyword
Separating Modules into Different Files
Packages and Crates
crate root = コンパイラがスタートするソースファイルでroot moduleをなすもの
package = 機能提供する1以上のcrate
Cargo.toml
at most 1 lib crate
as many bin crate
at least 1 crate
cargo newはパッケージを作る
src/main.rs, src/lib.rsがあるとbin crate, lib crate
src/bin
crateで名前を修飾して区別できる rand::Rngとか
Defining Modules to Control Scope and Privacy
Paths for Referring to an Item in the Module Tree
Bringing Paths Into Scope with the use Keyword
Separating Modules into Different Files